<!--
  ~ ***** BEGIN LICENSE BLOCK *****
  ~ Version: MPL 1.1
  ~
  ~ The contents of this file are subject to the Mozilla Public License Version
  ~ 1.1 (the "License"); you may not use this file except in compliance with
  ~ the License. You may obtain a copy of the License at
  ~ http://www.mozilla.org/MPL/
  ~
  ~ Software distributed under the License is distributed on an "AS IS" basis,
  ~ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  ~ for the specific language governing rights and limitations under the
  ~ License.
  ~
  ~ The Original Code is Topless JSF.
  ~
  ~ The Initial Developer of the Original Code is
  ~ Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
  ~ Portions created by the Initial Developer are Copyright (C) 2010
  ~ the Initial Developer. All Rights Reserved.
  ~
  ~ Contributor(s):
  ~
  ~ Marco Antonio Villalobos, Jr. (mvillalobos@kineteque.com).
  ~
  ~ ***** END LICENSE BLOCK *****
  -->
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:tfn="http://kineteque/topless/jsf"
    xmlns:topless="http://java.sun.com/jsf/composite/components/topless"
    xml:lang="en" lang="en">
<head>
    <title>Table Composite Component</title>
</head>
<body>
    <composite:interface componentType="kineteque.jsf.table">
        <composite:insertFacet name="ascOrder"/>
        <composite:insertFacet name="descOrder"/>
        <composite:insertFacet name="noOrder"/>
    </composite:interface>
    <composite:implementation>
        <c:if test="#{not empty cc.value}">
            <h:panelGroup id="req">
                <h:inputHidden id="includes" value="#{cc.includes}" converter="topless.jsonListConverter"/>
            </h:panelGroup>
            <h:dataTable id="t" binding="#{cc.table}" value="#{cc.value.list}" var="row" rows="#{cc.rows}">
                <f:facet name="header">
                    <h:panelGroup layout="block">
                        #{cc.first + 1} - #{cc.rows} of #{cc.value.rows} [ &nbsp;
                        <h:commandLink id="f" value="First" actionListener="#{cc.first}" immediate="true" disabled="#{empty cc.first or cc.first eq 0}">
                            <f:ajax render="t" execute="f"/>
                        </h:commandLink> &nbsp;|&nbsp;
                        <h:commandLink id="p" value="Previous" actionListener="#{cc.prev}" immediate="true" disabled="#{empty cc.first or cc.first eq 0}">
                            <f:ajax render="t" execute="p"/>
                        </h:commandLink> &nbsp;|&nbsp;
                        <h:commandLink id="n" value="Next" actionListener="#{cc.next}" immediate="true" disabled="#{(cc.first + cc.rows) ge cc.value.rows}">
                            <f:ajax render="t" execute="n"/>
                        </h:commandLink> &nbsp;|&nbsp;
                        <h:commandLink id="l" value="Last" actionListener="#{cc.last}" immediate="true" disabled="#{(cc.first + cc.rows) ge cc.value.rows}">
                            <f:ajax render="t" execute="l"/>
                        </h:commandLink> &nbsp;
                        ]
                    </h:panelGroup>
                </f:facet>

                <c:choose>
                    <c:when test="#{empty cc.children}">
                        <ui:decorate template="/resources/components/topless/columns.xhtml">
                            <ui:param name="first" value="0"/>
                            <ui:param name="columns" value="#{fn:length(cc.includes)}"/>
                            <ui:define name="ascSort"><composite:renderFacet name="ascOrder"/></ui:define>
                            <ui:define name="descSort"><composite:renderFacet name="descOrder"/></ui:define>
                            <ui:define name="noSort"><composite:renderFacet name="noOrder"/></ui:define>
                        </ui:decorate>
                    </c:when>
                    <c:otherwise>
                        <composite:insertChildren/>
                    </c:otherwise>
                </c:choose>

            </h:dataTable>
        </c:if>
    </composite:implementation>
</body>
</html>